/**
* Copyright (c) 2016-2100 yunclouds
*/
package com.yunqian.redot.repository;

import com.yunqian.redot.domain.Courses;
import com.yunqian.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * 课程管理
 *
 * @author zsy
 * 2018-09-29 15:54:02
 */
@Repository
public interface CoursesRepository extends BaseRepository<Courses, Long> {

    /**
     * 根据标题查找
     * @param title
     * @return
     */
    boolean existsByTitle(String title);

    /**
     * 根据报名时间设置状态
     */
    @Modifying
    @Query(value = "update t_courses set status = case when NOW() between begin_time and end_time then 2 when NOW() < begin_time then 1 when NOW() > end_time then 3 else status end where status <> 3", nativeQuery = true)
    void updateStatusByTime();

}
